﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevelopStudio.Basic;

namespace DevelopStudio.Control.FormPage
{
    public partial class AddBugs : Form
    {
        public BugInfo BugInfo { get; private set; }

        public AddBugs()
        {
            InitializeComponent();
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string message;
            if (this.ValidatePage(out message) == false)
            {
                MessageBox.Show(message);
                this.DialogResult = DialogResult.None;
                return;
            }

            try
            {
                BugInfo bugInfo = Utility.GetBugInfo(this.textBox1.Text);

                if (Utility.SupportCodeReviewBugs(bugInfo, out message) == false ||
                    Utility.IsBugBinding(bugInfo, out message) == true)
                {
                    MessageBox.Show(message);
                    this.DialogResult = DialogResult.None;
                    return;
                }

                BugInfo = bugInfo;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = DialogResult.None;
                return;
            }
        }

        protected bool ValidatePage(out string message)
        {
            message = string.Empty;

            if (string.IsNullOrEmpty(this.textBox1.Text) == true)
            {
                message = Properties.Resources.ErrorBugID;
                return false;
            }

            return true;
        }
    }
}
